package com.khh.dao;

import com.khh.entity.Book;
import com.khh.mapper.BookMapper;
import com.khh.mybatis.MybatisHelp;
import org.apache.ibatis.session.SqlSession;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017-08-25.
 */
public class BookDao implements BookMapper{

    private SqlSession session = new MybatisHelp().getSs();
    private BookMapper bm;

    public BookDao() {
        this.bm = session.getMapper(BookMapper.class);
    }

    public int insert(Book book) {
        int num = this.bm.insert(book);
        session.commit();
        session.close();
        return num;
    }

    public List<Book> queryall() {
        List<Book> books = this.bm.queryall();
        return books;
    }

    public int save(Map<String, Object> map) {
        int num = this.bm.save(map);
        session.commit();
        session.close();
        return num;
    }

    public int saves(String name, double price) {
        int num = this.bm.saves(name,price);
        session.commit();
        session.close();
        return num;
    }

    public List<Book> sel(){
        List<Book> books = this.bm.sel();
        return books;
    }


    @Override
    public void ins(String name, int price, String date) {
        this.bm.ins(name,price,date);
        session.commit();
        session.close();
    }

    /*@Override
    public int inser(String name, int price, String date) {

        int num = this.bm.inser(name,price,date);
        return num;
    }*/

    @Override
    public List<Book> page(int start, int size) {
        List<Book> books = this.bm.page(start,size);
        return books;
    }

    @Override
    public int getCount() {
        int m =this.bm.getCount();
        return m;
    }
}
